<?php
namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class BmrUserModel extends Model {
    use SoftDeletes;

    protected $table = 'bmr_users';

    protected $fillable = ['phone', 'name', 'id', 'sex'];

    /**根据手机号查找用户
     * @param $phone
     * @return mixed
     */
    public function findPhone($phone) {
        return $this->where('phone', $phone)->first();
    }

    /**lastBuilder
     * 最后一条评测
     */
    public function lastBuilder() {
        return $this->hasOne(UserBuilderModel::class, 'bmr_user_id', 'id')->orderByDesc('user_builder.id');
    }
}